package com.liuzu.esys.controller;

import com.liuzu.esys.common.LayuiPageVo;
import com.liuzu.esys.common.R;
import com.liuzu.esys.pojo.Bargain;

import com.liuzu.esys.pojo.Good;
import com.liuzu.esys.pojo.Vipmember;
import com.liuzu.esys.service.VipmemberService;
import org.apache.ibatis.jdbc.RuntimeSqlException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;
import java.util.Map;

/**
 * 会员特价层
 */
@RestController
@RequestMapping("/Vipmember")
public class VipmemberController {
    @Autowired
    private VipmemberService vipmemberService;
    //展示出所有会员特价商品
    @RequestMapping("/VipmemberList")
    public LayuiPageVo<Vipmember> VipmemberList(@RequestParam Map<String,Object> params){
        // 测试是否获取到参数时使用
        // System.out.println(params);
        return vipmemberService.pagingquery(params);
    }
    //添加特价商品操作
    @RequestMapping("/VipmemberAdd")
    public R VipmemberAdd(Vipmember vipmember){
        boolean flag = false;
        try {
        flag  = vipmemberService.vipmemberAdd(vipmember);
        }catch (RuntimeSqlException e){
            e.printStackTrace();
              return     R.error();
        }catch (Exception e){
             e.printStackTrace();
             return    R.error();
        }
        return R.ok();
    }

    /**
     *删除特价商品操作
     */
    @RequestMapping("/VipmemberDel")
    public R VipmemberDel(Integer id){

        int  a  = vipmemberService.vipmemberDel(id);
        if(a==1){
           return R.ok();
        }else {
           return R.error();
        }
    }
    /**
     * 批量删除特价信息
     */
    @RequestMapping("/VipmemberByIds")
    public R VipmemberByIds(String ids){
        boolean flag = false;
       flag =  vipmemberService.vipmemberByIds(ids);
       if(flag){
           return R.ok();
       }else {
           return R.error();
       }
    }
    //校验是否存在这个物品
    @RequestMapping("/VipmemberExamine")
    public R VipmemberExamine(String name){
        //根据 传来的名字查询是否有物品
        Good good =  vipmemberService.vipmemberExamineName(name);
        //根据 传来的名字查询是否有物品
        Vipmember vipmember = vipmemberService.vipmemberName(name);

        if(good != null && vipmember == null){
            return R.ok();
        }else {
            return R.error();
        }
    }

}
